﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Core = Microsoft.Office.Core;
using System.IO;
namespace ServerApp
{
   public class ControlPowerPoint
    {

        private PowerPoint.Application PPA;
        private PowerPoint.Presentation PPE;
        //String Path = "C:/Users/KimNhu/AppData/LocalLow/DATA/b.ppt";
       
        public void OpenPowerPoint(string filename)
        {
            String path = @"d:\";
            string[] a = filename.Split('\\');
            if (a.Length > 0)
            {
                path = filename;
            }
            else
            {
                filename = a[a.Length - 1];
                path += filename;
            }
            try
            {
               
               
                PPA = new PowerPoint.Application();
                PPA.WindowState = PowerPoint.PpWindowState.ppWindowNormal;
                //PPE = PPA.Presentations.Open(Path, Core.MsoTriState.msoFalse, Core.MsoTriState.msoFalse, Core.MsoTriState.msoTrue);
                PPE = PPA.Presentations.Open(path, Core.MsoTriState.msoFalse, Core.MsoTriState.msoFalse, Core.MsoTriState.msoTrue);
                PPE.SlideShowSettings.Run();
            }
            catch (Exception e)
            {
                
                throw new Exception(e.ToString());
            }
           
        }
        public void Next()
        {
            try
            {
                int sile = PPE.Slides.Count;
                PowerPoint.SlideShowView next = PPE.SlideShowWindow.View;
                next.Next();
            }
            catch (Exception e)
            {

                throw new Exception(e.ToString());
            }

           
        }
        public void Previous()
        {
            try
            {
                PowerPoint.SlideShowView previous = PPE.SlideShowWindow.View;
                previous.Previous();
            }
            catch (Exception e)
            {

                throw new Exception(e.ToString());
            }

            
        }
        public void Home()
        {
            try
            {
                PowerPoint.SlideShowView previous = PPE.SlideShowWindow.View;
                previous.First();
            }
            catch (Exception e)
            {

                throw new Exception(e.ToString());
            }

            

        }
        public void End()
        {
            try
            {
                PowerPoint.SlideShowView previous = PPE.SlideShowWindow.View;
                previous.Last();
            }
            catch (Exception e)
            {

                throw new Exception(e.ToString());
            }

            
        }
        public void Close()
        {
            try
            {

                PPA.Quit();
                PPE.Close();
            }
            catch (Exception e)
            {

                throw new Exception(e.ToString());
            }
            
        }
    }
}
